<template>
  <div class="">
    <h5>购物车列表</h5>
    <ul class="wrap">
      <li
        v-for="(item, index) in $store.state.shopcar"
        :key="index"
        class="con"
      >
        <p>{{ item.title }}</p>
        <p>{{ item.price }}</p>
        <el-input-number
          v-model="item.num"
          :min="1"
          @change="change"
        ></el-input-number>
        <span @click="remove(index)">x</span>
      </li>
    </ul>

    总价是{{ $store.getters.sum }}
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  created() {},
  methods: {
    change() {
      this.$store.commit("change");
    },
    remove(index) {
      this.$store.commit("remove", index);
    },
  },
  components: {},
};
</script>

<style lang="scss">
.wrap {
  width: 500px;
  margin: 100px auto;
}
.con {
  display: flex;
  justify-content: space-between;
  border: 1px solid #ccc;
}
</style>
